package alg20241128;

public class Text {
    public int deleteAndEarn(int[] nums) {
        int[] arr = new int[10001];
        //预处理
        for (int i = 0; i < nums.length; i++) {
            arr[nums[i]] += nums[i];
        }
        int n = arr.length;
        //1 创建表
        int[] f = new int[n];
        int[] g = new int[n];
        //2 初始化
        f[0] = arr[0];

        //3 填表
        for (int i = 1; i < n; i++) {
            f[i] = g[i - 1] + arr[i];
            g[i] = Math.max(f[i - 1] , g[i - 1]);
        }
        //4 返回值
        return Math.max(f[n-1], g[n-1]);

    }
}
